<?php

class Model_Orm_Review extends \Orm\Model
{
        protected static $_primary_key = array('id');
	protected static $_properties = array(
		'id',
		'movie_id',
		'user_id',
		'date',
		'rating',
		'review'
	);

	protected static $_table_name = 'reviews';
        
        protected static $_belongs_to = array(
            'movie' => array(
                'key_from' => 'movie_id',
                'model_to' => 'Model_Orm_Movie',
                'key_to' => 'id')
        );
        
        public static function validate($factory) {
            $val = Validation::forge($factory);

            $val->add_field('Review', 'Atsauksme', 'required|max_length[5000]|min_length[2]');
            $val->add_field('Rating', 'Vērtējums', 'required|numeric_min[0]|numeric_max[5]');
            $val->add_field('Movie_ID', 'Filmas ID', 'required|numeric_min[0]|numeric_max[10000]');

            return $val;
        }
}
